<?php
/**
 * Created by JetBrains PhpStorm.
 * User: mwasilewski
 * Date: 25.05.12
 * Time: 11:33
 * To change this template use File | Settings | File Templates.
 */
error_reporting(E_ALL ^ E_NOTICE);
require_once('stale_gry.php');
require_once('fanty.php');

function pokaz_formularz($fanty,$war)
{
    echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <meta content="text/html; charset=UTF-8" http-equiv="content-type" >
<html>
<head>
    <title>' . GRA_TYTUL . '</title>
</head>
<body>
    <h1>' . GRA_TYTUL . '</h1>
<form action="index.php" method="POST">
        <p>Imię:<input name="imie" type="TEXT" value="' . $_SESSION['imie'] . '"/></p>
        <p><select name="fant">';
    foreach ($fanty as $key => $fan)
        echo '<option value="' . $fan . '">' . $key . '</option>';
    echo '
        </select></p>
        <input name="wariant" type="hidden" value="'.$war.'">
        <p><input name="submit" type="submit"></p>
</form>
</body>
</html>
';
}

function sprawdz_formularz($fant,$moje_fanty,$wariant)
{
    echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <meta content="text/html; charset=UTF-8" http-equiv="content-type" >
<html>
<head>
    <title>' . GRA_TYTUL . '</title>
</head>
<body>
    <h1>' . GRA_TYTUL . '</h1>';
if($fant != "pusty los"){
    echo $_SESSION['imie']." wygrana";
    array_push($_SESSION['moje_fanty'],$fant);
    foreach($_SESSION['moje_fanty'] as $fa)
        echo '<p> - '.$fa.'</p>';
    echo '<a href="index.php?wariant='.$wariant.'">Następny fant</a> ';
} else {
    echo $_SESSION['imie']." przegrana - Twoje fanty to:";
    foreach($_SESSION['moje_fanty'] as $fa)
        echo '<p> - '.$fa.'</p>';
    echo '<a href="index.php?wariant='.$wariant.'">Nowa gra</a> ';
    session_unset();
}
}

import_request_variables("pg","");
session_start();
$_SESSION['moje_fanty'] = (isset($_SESSION['moje_fanty'])) ? $_SESSION['moje_fanty'] : array();

if (!$submit) {
    pokaz_formularz($$wariant,$wariant);
} else {
    $_SESSION['imie'] = $imie;
    sprawdz_formularz($fant,$_SESSION['moje_fanty'],$wariant);
}